<template>
  <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancel" :visible.sync="dialog"
             title="题库列表信息"
             append-to-body width="70%">
    <div class="head-container">
        <el-input v-model="bankName" clearable placeholder="输入题库名称"  size="medium" maxlength="10" style="width: 200px;margin-top: -19px;"
                  class="filter-item" @keyup.enter.native="init"/>
        <div  style="display: inline-block;" >
          <treeselect v-model="specialtyId" class="treeselect-main"  :options="specialty" :normalizer="normalizer" placeholder="选择专业"/>
        </div>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="init" style="margin-top: -18px;">搜索</el-button>
    </div>
    <el-table ref="table" v-loading="loading" :data="data" size="small" style="width: 100%;" border>
      <el-table-column type="selection" width="55"/>
      <el-table-column label="题库名称" prop="bankName" show-overflow-tooltip/>
      <el-table-column label="包含专业" prop="specialtyName" show-overflow-tooltip align="center"/>
      <el-table-column label="总题数" prop="total" width="110" align="center"/>
      <el-table-column label="单选题" prop="danxuan" width="110" align="center"/>
      <el-table-column label="多选题" prop="duoxuan" width="110" align="center"/>
      <el-table-column label="判断题" prop="panduan" width="110" align="center"/>
     <!-- <el-table-column label="题库描述" prop="bankDesc" show-overflow-tooltip/> -->
    </el-table>
    <el-pagination
      :total="total"
      :current-page="page + 1"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="okSelect">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import initData from '@/mixins/initData'
  import { tree } from '@/api/framework/system/specialty'
  import Treeselect from '@riophae/vue-treeselect'
  import '@riophae/vue-treeselect/dist/vue-treeselect.css'

  export default {
    components: { Treeselect },
    name: 'questionBank',
    mixins: [initData],
    data() {
      return {
        dialog: false,
        bankName: '',
        specialtyId:null,
        jobId:'',
        specialty: []
      }
    },
    created() {
      this.$nextTick(() => {
        this.getSpecialtyType()
      })
    },
    methods: {
      normalizer(node) {
        if (node.children && !node.children.length) {
          delete node.children
        }
      },
      cancel() {
        this.dialog = false
      },
      beforeInit() {
        this.url = 'question/bank-list-total'
        this.params = { page: this.page, size: this.size,type:1, bankName: this.bankName,specialtyId:this.specialtyId }
        return true
      },
      okSelect() {
        const data = this.$refs.table.selection
        const questionInfo = []
        for (let i = 0; i < data.length; i++) {
          const user = { bankId: data[i].id, bankName: data[i].bankName, bankDesc: data[i].bankDesc }
          questionInfo.push(user)
        }
        this.$emit('setQuestionInfo', questionInfo)
        this.cancel()
      },
      getSpecialtyType() {
        tree().then(data => {
          this.specialty = []
          const type = { id: '0', label: '专业类型', children: [] }
          type.children = data
          this.specialty.push(type)
        })
      },
    }
  }
</script>

<style>
.treeselect-main {
    margin-top: 1px;
    line-height: 34px;
    width: 200px;
    .vue-treeselect__placeholder {
      line-height: 34px;
    }
    .vue-treeselect__control {
      height: 35px;
    }
  }
.el-dialog__body{
  padding: 10px 10px
}

</style>
